import json

# (1) 读取json.txt中的信息
with open('json.txt', 'r', encoding='utf-8') as file:
    users_data = json.load(file)

# (2) 创建UserInfo类并封装数据
class UserInfo:
    def __init__(self, username, age, email, register_date):
        self.username = username
        self.age = age
        self.email = email
        self.register_date = register_date

    def __str__(self):
        return f"用户名: {self.username}, 年龄: {self.age}, 邮箱: {self.email}, 注册日期: {self.register_date}"

# (3) 将所有用户信息封装并存入列表
user_list = []
for user_data in users_data:
    user = UserInfo(
        username=user_data['username'],
        age=user_data['age'],
        email=user_data['email'],
        register_date=user_data['register_date']
    )
    user_list.append(user)

# (4) 遍历列表输出所有用户信息
print("所有用户信息：")
for user in user_list:
    print(user)  # 这里会自动调用__str__方法